import os

from celery import Celery
from celery.schedules import crontab

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swim_api.settings.dev")

broker = 'redis://127.0.0.1:6379/1'
backend = 'redis://127.0.0.1:6379/2'

app = Celery(__name__, backend=backend, broker=broker, include=[
    'celery_task.home_task'
])
app.conf.timezone = 'Asia/Shanghai'
app.conf.enable_utc = False

# 配置定时任务
app.conf.beat_schedule = {
    # 'update_banner_every_5_seconds': {
    #     'task': 'celery_task.home_task.update_banner',
    #     'schedule': timedelta(seconds=5),
    # },
    'update_num_everyday': {
        'task': 'celery_task.home_task.update_num',
        'schedule': crontab(minute=55, hour=23),
    },
    'update_open_everyday': {
        'task': 'celery_task.home_task.update_open',
        'schedule': crontab(minute=00, hour=8),
    },
    'update_close_everyday': {
        'task': 'celery_task.home_task.update_close',
        'schedule': crontab(minute=00, hour=21),
    },
}
